package com.ks.app.admin.service.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Service;

import com.ks.app.admin.hibernate.KsProvinceInfo;
import com.ks.app.admin.hibernate.KsProvinceSmsc;
import com.ks.app.admin.service.ProvinceService;

@Service("provinceService")
public class ProvinceServiceImpl  extends BaseServiceImpl implements ProvinceService {
	
//获得所有省份
	@SuppressWarnings("unchecked")
	public List<KsProvinceInfo> selectProvince() 
	{		
		String sql = "from KsProvinceInfo t";
		Query query = em.createQuery(sql);
		return query.getResultList();
	}
	//根据名称获得省份
	public KsProvinceInfo selectpname(String name) { 
		String sql = "from KsProvinceInfo t where instr(t.provincename,?)>0";
		
        Query query = em.createQuery(sql);
        query.setParameter(1, name);
		
		return (KsProvinceInfo) query.getSingleResult();
	}
	
	public KsProvinceSmsc getpidbysmsc(String smsc)
	{
		if(smsc!=null&&smsc.trim().length()>0)
		{
			String sql = "from KsProvinceSmsc t where smsc='"+smsc+"'";		
	        Query query = em.createQuery(sql);		
			return (KsProvinceSmsc) query.getSingleResult();
		}
		return null;
	}
}
